#include<bits/stdc++.h>
using namespace std;
#define int long long

int tri[1005][1005];

signed main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			cin >> tri[i][j];
			tri[i][j] += max(tri[i - 1][j], tri[i - 1][j - 1]);
		}
	}
	cout << *max_element(&tri[n][1], &tri[n][n + 1]);
	return 0;
}
